import request from "@/api/request";

/**
 * 获取列表
 * @param params 参数
 */
export function getList(params: SearchListParams) {
  return request({
    url: "/system/user/page",
    method: "get",
    params: params,
  });
}

/**
 * 获取详情
 * @param params 参数
 */
export function getInfo(params: number) {
  return request({
    url: "/system/user/" + params,
    method: "get"
  });
}

/**
 * 新增
 * @param params 参数
 */
export function saveInfo(params: DataInfo) {
  return request({
    url: "/system/user/save",
    method: "post",
    data: params,
  });
}

/**
 * 修改
 * @param params 参数
 */
export function editInfo(params: DataInfo) {
  return request({
    url: "/system/user/update",
    method: "post",
    data: params,
  });
}

/**
 * 修改密码
 * @param params 参数
 */
export function editPassword(params: EditPasswordForm) {
  return request({
    url: "/system/user/editPassword",
    method: "post",
    data: params,
  });
}

/**
 * 重置密码
 * @param params 参数
 */
export function resetPassword(params: RestPasswordForm) {
  return request({
    url: "/system/user/resetPassword",
    method: "post",
    data: params,
  });
}

/**
 * 删除
 * @param params 参数
 */
export function deleteInfo(params: number | number[]) {
  return request({
    url: "/system/user/remove/" + params.toString(),
    method: "get"
  });
}

/**
 * 获取用户角色
 * @param params 参数
 */
export function listUserRole(params: {roleId: number | null,userId: number | null}) {
  return request({
    url: "/system/user/listUserRole",
    method: "get",
    params: params,
  });
}

/**
 * 修改用户角色
 * @param params 参数
 */
export function editUserRole(params: {roleIds: number[],userId: number | null}) {
  return request({
    url: "/system/user/editUserRole",
    method: "post",
    data: params,
  });
}

export interface SearchListParams {
    pageNum: number;
    pageSize: number;
    username: string;
    nickName: string;
    phone: string;
    email: string;
    address: string;
}

export interface DataInfo {
    id: number | null;
    username: string;
    password: string;
    nickName: string;
    phone: string;
    email: string;
    address: string;
    profilePicture: string;
}

export interface TableData {
    id: number;
    username: string;
    nickName: string;
    phone: string;
    email: string;
    address: string;
    createTime: string;
    updateTime: string;
}

export interface EditPasswordForm {
    oldPassword: string;
    newPassword: string;
    confirmPassword: string;
}

export interface RestPasswordForm {
    userId: number | null;
    password: string;
}